/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
*/

package com.chasekernan.hxnova.core.components;

import com.chasekernan.hxnova.core.components.ComponentSet;
import haxe.xml.Check;
import com.chasekernan.hxnova.core.minerals.MineralSet;
import com.chasekernan.hxnova.core.races.TechLevel;

/**
    Cargo pod emulates both just pure cargo pods and fuel pods.
**/
class CargoPod extends Component {
    
    public var mineralCapacity(default, setMCapacity) : Int;
    private function setMCapacity(i : Int) : Int {if(i < 0) {throw "MineralCapacity must be >= 0.";} else {mineralCapacity = i;} return mineralCapacity;}
    
    public var fuelCapacity(default, setFCapacity) : Int;
    private function setFCapacity(i : Int) : Int {if(i < 0) {throw "FuelCapacity must be >= 0.";} else {fuelCapacity = i;} return fuelCapacity;}
    
    public function new(name : String, ?mineralCapacity : Int, 
            ?fuelCapacity : Int) {
        super(name);
        setMCapacity(if(mineralCapacity == null) 0 else mineralCapacity);
        setFCapacity(if(fuelCapacity == null) 0 else fuelCapacity);
    }
    
    public static function writeToXml(cp : CargoPod) : Xml {
        return Component.writeToXml(cp);
    }
    
    public static function readFromXml(xml : Xml) : CargoPod {
        try {
            var cp = new CargoPod("");
           // Check.checkNode(xml, cp.getRules());
            cp.generateFromComponentXml(xml, cp);
            
            return cp;
        } catch (e : Dynamic) {
            throw 'Bad xml file for cargo pod: ' + e;
        }
    }
}